package com.yulongtian.oneProblemEveryDay.month202302;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/
 * 可
 *
 * @author yulongTian
 * @create 2023-02-11 12:59
 */
public class Test08 {
    public static void main(String[] args) {
        int[] arr = {5, 4, 4};
        System.out.println(fillCups(arr));
    }

    public static int fillCups(int[] amount) {
        int ans = 0;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        priorityQueue.add(amount[0]);
        priorityQueue.add(amount[1]);
        priorityQueue.add(amount[2]);
        while (true) {
            int a = priorityQueue.poll();
            int b = priorityQueue.poll();
            if (a != 0 && b != 0) {
                ans++;
                a--;
                b--;
                priorityQueue.add(a);
                priorityQueue.add(b);
            } else {
                ans += a + b;
                break;
            }
        }
        return ans;
    }

}
